{include file="/public/header"}
<style>
    .new-project-list-item{
        background-color: #fff;
        border: 1px dashed #dcdee2;
        border-radius: 4px;
        cursor: pointer;
        transition: all .2s;
        color: #515a6e;
    }
    .new-project-list-item:hover{
        border-color: #2d8cf0;
        color: #2d8cf0;
        box-shadow: 0 2px 10px rgb(45, 139, 239);
    }
    /** 项目列表样式 */
    .project-list-item {
        background-color: #fff;
        border: 1px solid #e8e8e8;
        border-radius: 4px;
        cursor: pointer;
        transition: all .2s;
    }

    .project-list-item:hover {
        box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
    }

    .project-list-item .project-list-item-cover {
        width: 100%;
        height: 220px;
        display: block;
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
    }

    .project-list-item-body {
        padding: 20px;
    }

    .project-list-item .project-list-item-body > h2 {
        font-size: 18px;
        color: #333;
        margin-bottom: 12px;
    }

    .project-list-item .project-list-item-text {
        height: 44px;
        overflow: hidden;
        margin-bottom: 12px;
    }

    .project-list-item .project-list-item-desc {
        position: relative;
    }

    .project-list-item .project-list-item-desc .time {
        color: #999;
        font-size: 12px;
    }

    .project-list-item .project-list-item-desc .ew-head-list {
        position: absolute;
        right: 0;
        top: 0;
    }

    .ew-head-list .ew-head-list-item {
        width: 22px;
        height: 22px;
        border-radius: 50%;
        border: 1px solid #fff;
        margin-left: -10px;
    }

    .ew-head-list .ew-head-list-item:first-child {
        margin-left: 0;
    }

    /** // 项目列表样式结束 */
    .mask{position:fixed;width:100%;height:100%;top:0;left:0;background:#000;opacity:0.8;filter:alpha(Opacity=80);-moz-opacity:0.8;z-index:999;display:none;}
    .loading{position:fixed;width:300px;left:50%;margin-left:-150px;top:200px;height:18px;border-radius:10px;background:#fff;z-index:9999;overflow:hidden;display:none;}

</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding-top: 20px;">
            <div class="layui-row layui-col-space30" id="demoCardList1">
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="demoCardItem2">
    <div class="layui-col-md3">
        <a lay-filter="SF_InstallSubmit" class="new-project-list-item" style="height: 377px;display: flex;align-items: center;justify-content: center" lay-submit>
            <i class="layui-icon layui-icon-addition"></i>&nbsp;新增插件
        </a>
    </div>
</script>
<script type="text/html" id="demoCardItem1">
    <div class="layui-col-md3">
        <div class="project-list-item">
            <img class="project-list-item-cover" src="{{d.img?d.img:'{__IMG__}/logo.png'}}" style="object-fit: cover;object-position: 50% 20%;"/>
            <div class="project-list-item-body">
                <h2>{{d.title}}<span class="pull-right">V {{d.version}}</span></h2>
                <div class="project-list-item-text layui-text">{{d.description}}</div>
                <div class="project-list-item-desc">
                    <span class="time">{{d.author}}</span>
                    <div class="ew-head-list">
                        <img class="ew-head-list-item" lay-tips="{{d.author}}" lay-offset="0,-5px"
                             src="//q4.qlogo.cn/headimg_dl?dst_uin={{d.qq}}&spec=100"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="SF_ConfigDialog">
    <style>
        .layui-form-switch {
            position: relative;
            height: 42px;
            line-height: 42px;
            min-width: 85px;
            padding: 0 5px;
            margin-top: 8px;
            border: 1px solid #d2d2d2;
            border-radius: 40px;
            cursor: pointer;
            background-color: #fff;
            -webkit-transition: .1s linear;
            transition: .1s linear;
        }
        .layui-form-switch i {
            position: absolute;
            left: 8px;
            top: 5px;
            width: 32px;
            height: 32px;
            border-radius: 20px;
            background-color: #d2d2d2;
            -webkit-transition: .1s linear;
            transition: .1s linear;
        }
        .layui-form-onswitch i {
            left: 100%;
            margin-left: -40px;
            background-color: #fff;
        }

    </style>
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-col-space10" id="SF_ConfigForm" lay-filter="SF_ConfigForm">
                <div class="layui-col-md6">
                    <a lay-filter="SF_ConfigSubmit" lay-submit>
                        <div class="project-list-item" style="text-align: center" lay-tips="插件设置">
                            <div style="margin-top: 35px;margin-bottom: 35px">
                                <svg t="1657105945926" class="icon" viewBox="0 0 1030 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1822" width="80" height="80"><path d="M943.321212 577.163636c12.412121 18.618182 31.030303 31.030303 55.854546 37.236364 6.206061 0 12.412121 6.206061 12.412121 6.206061 6.206061 6.206061 18.618182 18.618182 18.618182 31.030303v24.824242c-6.206061 24.824242-12.412121 43.442424-24.824243 62.060606l-6.20606 12.412121c-6.206061 12.412121-12.412121 18.618182-24.824243 24.824243-6.206061 6.206061-18.618182 6.206061-24.824242 6.20606-6.206061 0-12.412121 0-18.618182-6.20606-18.618182-6.206061-37.236364-6.206061-55.854546-6.206061h6.206061-12.412121c-18.618182 0-31.030303 6.206061-43.442424 12.412121 0 0-12.412121 6.206061-24.824243 18.618182-12.412121 12.412121-24.824242 37.236364-24.824242 62.060606 0 18.618182 0 37.236364 12.412121 62.060606 6.206061 12.412121 6.206061 31.030303-6.206061 43.442425-12.412121 12.412121-24.824242 18.618182-37.236363 24.824242-6.206061 6.206061-37.236364 18.618182-68.266667 24.824242 37.236364-6.206061 12.412121 0-12.412121 0h-6.206061c-6.206061 0-12.412121 0-18.618182-6.20606-6.206061-6.206061-12.412121-12.412121-12.412121-24.824243v6.206061c-12.412121-31.030303-31.030303-55.854545-55.854545-68.266667 0-6.206061-24.824242-12.412121-49.648485-12.412121s-49.648485 6.206061-68.266667 24.824243c-24.824242 18.618182-43.442424 43.442424-49.648485 74.472727 0-6.206061-6.206061 0-12.412121 0 0 0-12.412121 6.206061-18.618182 6.20606-12.412121 0-18.618182 0-37.236363-6.20606-12.412121-6.206061-24.824242-6.206061-37.236364-12.412121l-37.236364-18.618182c-12.412121-6.206061-18.618182-12.412121-24.824242-24.824243-6.206061-6.206061-6.206061-12.412121-6.206061-18.618181 0-6.206061 0-18.618182 6.206061-31.030304 6.206061-6.206061 12.412121-24.824242 12.412121-49.648484s-12.412121-43.442424-31.030303-62.060606c-12.412121-12.412121-24.824242-18.618182-43.442424-24.824243h-24.824242-6.206061c-12.412121 0-31.030303 6.206061-49.648485 6.206061h-12.412121c-6.206061 0-12.412121 0-18.618182-6.206061-6.206061 0-12.412121-12.412121-24.824242-18.618182-18.618182-31.030303-31.030303-68.266667-37.236364-105.50303v-6.206061c0-18.618182 12.412121-24.824242 24.824242-31.030303 24.824242-6.206061 43.442424-24.824242 62.060606-43.442424 18.618182-6.206061 24.824242-31.030303 24.824243-55.854545s-6.206061-49.648485-24.824243-68.266667C62.060606 415.806061 31.030303 397.187879 0 390.981818c18.618182 6.206061 12.412121 0 12.412121-6.20606-6.206061-6.206061-6.206061-18.618182-6.20606-24.824243 0-6.206061 0-18.618182 6.20606-31.030303 6.206061-24.824242 18.618182-49.648485 31.030303-68.266667-12.412121 24.824242-6.206061 12.412121 0 6.206061 0-12.412121 6.206061-18.618182 12.412121-24.824242 6.206061 0 6.206061-6.206061 12.412122-6.206061s12.412121 0 18.618181 6.206061c24.824242 6.206061 49.648485 12.412121 74.472728 6.20606 24.824242 0 43.442424-12.412121 62.060606-31.030303 12.412121-12.412121 18.618182-24.824242 18.618182-43.442424 6.206061 0 6.206061-12.412121 6.20606-24.824242v-18.618182-18.618182c0-18.618182-6.206061-43.442424-12.412121-62.060606 6.206061 31.030303 0 18.618182 0 6.20606v0c12.412121-6.206061 18.618182-12.412121 31.030303-18.618181l37.236364-18.618182c12.412121-6.206061 24.824242-6.206061 37.236363-12.412121 12.412121-6.206061 24.824242-6.206061 31.030303-6.206061 12.412121 0 18.618182 0 24.824243 12.412121 6.206061 6.206061 12.412121 18.618182 12.412121 31.030303 6.206061 12.412121 18.618182 24.824242 37.236364 43.442424s37.236364 24.824242 62.060606 24.824243 49.648485-6.206061 68.266666-18.618182c24.824242-24.824242 37.236364-43.442424 43.442425-68.266667 0-6.206061 6.206061-12.412121 12.412121-18.618181 6.206061 0 12.412121-6.206061 18.618182-6.206061 12.412121 0 18.618182 0 31.030303 6.206061 12.412121 0 24.824242 6.206061 37.236363 12.412121 12.412121 6.206061 24.824242 12.412121 31.030303 18.618182 12.412121 6.206061 18.618182 18.618182 24.824243 24.824242 0 6.206061 6.206061 6.206061 6.20606 12.412121v6.206061c0 6.206061-6.206061 18.618182-6.20606 24.824242 0 6.206061-6.206061 24.824242-6.206061 37.236364v18.618182c6.206061 24.824242 12.412121 43.442424 31.030303 62.060606 18.618182 18.618182 37.236364 24.824242 62.060606 31.030303 24.824242 0 49.648485 0 68.266667-12.412121 6.206061 0 12.412121-6.206061 18.618182-6.206061h6.20606c6.206061 0 18.618182 6.206061 24.824243 12.412121 12.412121 12.412121 18.618182 24.824242 31.030303 43.442424 6.206061 18.618182 12.412121 43.442424 18.618182 62.060607 0 12.412121 0 24.824242-6.206061 31.030303-6.206061 6.206061-12.412121 12.412121-24.824242 18.618181-24.824242 6.206061-49.648485 31.030303-62.060606 55.854546-6.206061 6.206061-12.412121 24.824242-12.412122 49.648485-6.206061 24.824242 0 49.648485 18.618182 68.266666zM682.666667 341.333333c-43.442424-43.442424-105.50303-68.266667-167.563637-68.266666-31.030303 0-62.060606 6.206061-93.090909 18.618181-43.442424 18.618182-80.678788 49.648485-105.50303 86.884849-6.206061-6.206061-24.824242 37.236364-37.236364 80.678788 0-18.618182-6.206061 12.412121-6.20606 49.648485 0 31.030303 6.206061 62.060606 18.618181 93.090909 12.412121 31.030303 31.030303 55.854545 49.648485 74.472727 18.618182 24.824242 49.648485 37.236364 74.472728 49.648485 31.030303 12.412121 62.060606 18.618182 93.090909 18.618182s62.060606-6.206061 93.090909-18.618182c43.442424-18.618182 80.678788-49.648485 105.50303-86.884849-6.206061 12.412121 12.412121-12.412121 24.824243-43.442424 12.412121-31.030303 18.618182-62.060606 18.618181-93.090909s-6.206061-62.060606-18.618181-93.090909C713.69697 372.363636 682.666667 335.127273 645.430303 310.30303l37.236364 31.030303z" p-id="1823" fill="#707070"></path></svg>
                            </div>
                        </div>
                    </a>
                </div>
                <div class="layui-col-md6">
                    <a lay-filter="SF_DeleteSubmit" lay-submit>
                        <div class="project-list-item" style="text-align: center" lay-tips="插件卸载">
                            <div style="margin-top: 35px;margin-bottom: 35px">
                                <svg t="1657106858978" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3893" width="80" height="80"><path d="M853.4 333.5H199.8c-3.9 0-7 3.4-6.6 7.3l60.1 630c0 29.3 23.8 53.1 53.1 53.1H747c29.3 0 53.1-23.8 53.1-53.1l60.1-630c0.2-3.9-2.8-7.3-6.8-7.3zM388.8 890.9h-19.5c-13 0-23.6-10.6-23.6-23.6l-24.3-376c0-13 10.6-23.6 23.6-23.6h19.5c13 0 23.6 10.6 23.6 23.6l24.3 376c0 13-10.6 23.6-23.6 23.6z m171.3-23.6c0 13-10.6 23.6-23.6 23.6H517c-13 0-23.6-10.6-23.6-23.6v-376c0-13 10.6-23.6 23.6-23.6h19.5c13 0 23.6 10.6 23.6 23.6v376z m148.3 0c0 13-10.6 23.6-23.6 23.6h-19.5c-13 0-23.6-10.6-23.6-23.6l24.3-376c0-13 10.6-23.6 23.6-23.6h19.5c13 0 23.6 10.6 23.6 23.6l-24.3 376zM869.3 153.2l-705 162c-4 0.9-7.9-1.6-8.8-5.5l-8.8-38.5c-6.8-29.5 11.8-59.2 41.3-66L800 64.5c29.5-6.8 59.2 11.8 66 41.3l8.8 38.5c0.9 4-1.5 8-5.5 8.9zM386.5 127.3c-6.5-27.9 11-56.1 39-62.6l98.2-22.8c27.9-6.5 56.1 11 62.6 39l3.8 16.2 44.3-10.3-3.1-13.3c-11.7-50.4-62.5-82-112.8-70.3L413.6 27.6c-50.4 11.7-82 62.5-70.3 112.8l3 13.1 43.9-10.2-3.7-16z" p-id="3894" fill="#ff5722"></path></svg>
                            </div>
                        </div>
                    </a>
                </div>
                <div class="layui-col-md6">
                    <div class="project-list-item" style="text-align: center" lay-tips="插件开关">
                        <div class="layui-form" style="margin-top: 52px;margin-bottom: 53px">
                            <input type="checkbox" name="status" value="1" lay-skin="switch" lay-filter="SF_Status"/>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <a lay-filter="SF_UpdateSubmit" lay-submit>
                        <div class="project-list-item" style="text-align: center" lay-tips="插件更新">
                            <div style="margin-top: 35px;margin-bottom: 35px">
                                <svg t="1657107142618" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="16782" width="80" height="80"><path d="M768 810.7H512c-23.6 0-42.7-19.1-42.7-42.7s19.1-42.7 42.7-42.7h256c94.1 0 170.7-76.6 170.7-170.7 0-89.6-70.1-164.3-159.5-170.1L754 383l-10.7-22.7c-42.2-89.3-133-147-231.3-147s-189.1 57.7-231.3 147L270 383l-25.1 1.6c-89.5 5.8-159.5 80.5-159.5 170.1 0 94.1 76.6 170.7 170.7 170.7 23.6 0 42.7 19.1 42.7 42.7s-19.1 42.7-42.7 42.7c-141.2 0-256-114.8-256-256 0-126.1 92.5-232.5 214.7-252.4C274.8 195.7 388.9 128 512 128s237.2 67.7 297.3 174.2C931.5 322.1 1024 428.6 1024 554.7c0 141.1-114.8 256-256 256z" fill="#3688FF" p-id="16783"></path><path d="M554.7 938.7c-10.9 0-21.8-4.2-30.2-12.5l-128-128c-16.7-16.7-16.7-43.7 0-60.3l128-128c16.6-16.7 43.7-16.7 60.3 0 16.7 16.7 16.7 43.7 0 60.3L487 768l97.8 97.8c16.7 16.7 16.7 43.7 0 60.3-8.3 8.4-19.2 12.6-30.1 12.6z" fill="#5F6379" p-id="16784"></path></svg>
                            </div>
                        </div>
                    </a>
                </div>
            </form>
        </div>
    </div>
</script>
<script type="text/html" id="SF_TbUpload">
    <div class="layui-card">
        <div class="layui-card-body layui-form-pane">
            <form class="layui-form" method="post" action="">
                <div class="layui-form-item text-center">
                    <div class="layui-upload-drag" id="fileUpload">
                        <i class="layui-icon layui-icon-upload-drag" style="color:#2d8cf0;"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                        <div class="layui-hide" id="uploadDemoView">
                            <hr>
                            <div class="layui-form-item">
                                <img src="" alt="上传成功后渲染" id="demo1" style="max-width: 196px">
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">文件名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" id="name" value="" lay-verify="title" autocomplete="off" readonly="true" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</script>
<script type="text/html" id="SF_DeleteDialog">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" id="SF_DeleteForm" lay-filter="SF_DeleteForm">
                <input type="hidden" name="name">
                <div class="sf-tag layui-badge-orange" style="font-size: 15px">
                    确定要卸载该插件？
                </div>
                <div class="layui-form-item"></div>
                <div class="layui-form-item">
                    <input type="checkbox" name="droptables" value="1" title="删除相关数据库" lay-skin="primary">
                </div>
                <div class="layui-form-item text-right">
                    <button class="layui-btn" lay-filter="SF_UninstallSubmit" lay-submit>确定</button>
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                </div>
            </form>
        </div>
    </div>
</script>
{include file="/public/footer"}
<script>
    layui.use(['layer', 'form', 'dataGrid', 'element', 'dropdown', 'notice', 'admin', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var dataGrid = layui.dataGrid;
        var notice = layui.notice;
        var admin = layui.admin;
        var upload = layui.upload;
        var element = layui.element;

        function list(){
            notice.msg('正在执行中..', {icon: 4, close: true});
            $.ajax({
                type: "POST",
                url: '{:url("/Addon/list")}',
                async: false,
                dataType: "json",
                success: function(data) {
                    notice.destroy();
                    notice.msg("获取列表成功！", {icon: 1});
                    dataGrid.render({
                        elem: '#demoCardList1',
                        templet: '#demoCardItem1',
                        data: data.data,
                        page: {limit: 7, limits: [8, 16, 24, 32, 40]}
                    });
                    $("#demoCardList1").prepend($("#demoCardItem2").html());
                },
                error: function() {
                    notice.destroy();
                    notice.msg("服务器错误！", {icon: 2});
                }
            });
        }
        // 项目
        $(function (){
            list();
        });

        form.on('submit(SF_InstallSubmit)', function (data) {
            admin.open({
                title: '上传插件安装包',
                type: 1,
                content: $('#SF_TbUpload').html(),
                success: function (){
                    upload.render({
                        elem: '#fileUpload',
                        url: '{:url("/Addon/local")}', //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                        accept: 'file',
                        acceptMime: '*.*',//允许上传的文件类型
                        done: function(res){
                            if(res.code == 0){
                                layer.closeAll();
                                list();
                                notice.msg('插件安装成功', {icon: 1});
                            }else{
                                notice.msg(res.msg, {icon: 2});
                            }
                        }
                    });
                }
            });
        });

        form.on('submit(SF_UninstallSubmit)', function (data) {
            layer.confirm('<div style="color: red">卸载将会删除所有插件文件且不可找回!!!</div><br><span style="color: red">如有重要数据请备份后再操作!!!</span>', {
                skin: 'layui-layer-admin',
                icon: 3,
                shade: .1,
                btn: ['确认删除','取消'],
                title: '删除确认',
            }, function (i) {
                notice.msg('正在执行中..', {icon: 4, close: true});
                $.ajax({
                    type: "POST",
                    url:'{:url("/Addon/unInstall")}',
                    data: data.field,
                    dataType: "json",
                    success: function(data) {
                        layer.closeAll();
                        notice.destroy();
                        if (data.code == 0) {
                            list();
                            notice.msg(data.msg, {icon: 1, audio:'1'});
                        }else{
                            notice.msg(data.msg, {icon: 2, audio:'1'});
                        }
                    },
                    error: function() {
                        notice.destroy();
                        notice.msg("服务器错误！", {icon: 2, audio:'1'});
                    }
                });
            });
            return false;
        });
        dataGrid.on('item(demoCardList1)', function (obj) {
            admin.open({
                type: 1,
                title: '插件 - ' + obj.data.title,
                content: $('#SF_ConfigDialog').html(),
                success: function (layero, dIndex) {
                    form.val('SF_ConfigForm',{status:parseInt(obj.data.status)});
                    form.render('checkbox');
                    form.on('submit(SF_ConfigSubmit)', function (data) {
                        admin.open({
                            type: 2,
                            title: '插件 - '+obj.data.title+'配置',
                            maxmin: true,
                            area: ['500px','500px'],
                            content: '{:url("/Addon/config")}?name=' + obj.data.name,
                            success: function (layero, dIndex) {

                            }
                        });
                    });

                    form.on('submit(SF_UpdateSubmit)', function (data) {
                        admin.open({
                            title: '上传插件更新包',
                            type: 1,
                            content: $('#SF_TbUpload').html(),
                            success: function (){
                                upload.render({
                                    elem: '#fileUpload',
                                    url: '{:url("/Addon/update")}', //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                                    accept: 'file',
                                    data: {'name':obj.data.name},
                                    acceptMime: '*.*',//允许上传的文件类型
                                    done: function(res){
                                        if(res.code == 0){
                                            layer.closeAll();
                                            list();
                                            notice.msg('插件更新成功', {icon: 1});
                                        }else{
                                            notice.msg(res.msg, {icon: 2});
                                        }
                                    }
                                });
                            }
                        });
                    });

                    form.on('submit(SF_DeleteSubmit)', function (data) {
                        admin.open({
                            type: 1,
                            icon: 3,
                            title: '插件 - '+obj.data.title+'卸载',
                            shade: .1,
                            content: $("#SF_DeleteDialog").html(),
                            success: function (layero, dIndex) {
                                form.render('checkbox');
                                $("#addon_name").text(obj.data.name);
                                $("input[name='name']").val(obj.data.name);
                            }
                        });
                    });

                    form.on('switch(SF_Status)', function (data) {
                        notice.msg('正在执行中..', {icon: 4, close: true});
                        $.ajax({
                            type: "POST",
                            url:'{:url("/Addon/status")}',
                            data: {name:obj.data.name,action:data.elem.checked ? 'enable' : 'disable'},
                            dataType: "json",
                            success: function(data) {
                                notice.destroy();
                                if (data.code == 0) {
                                    list();
                                    notice.msg(data.msg, {icon: 1, audio:'1'});
                                }else{
                                    notice.msg(data.msg, {icon: 2, audio:'1'});
                                }
                            },
                            error: function() {
                                notice.destroy();
                                notice.msg("服务器错误！", {icon: 2, audio:'1'});
                            }
                        });
                    });
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                }
            });
        });
    });
</script>